package com.sensePlusVR.testActivity;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.widget.Button;

import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.MyLog;
@SuppressLint("InlinedApi")
@SuppressWarnings("unused")
public class MainTestActivity extends Activity{
	
	private Handler mHandeler;

	private Button mButton;
	
	private static final long delay = 3000;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		mHandeler = new Handler(Looper.getMainLooper());

		
		
		setContentView(R.layout.main_test);
		
		
	
		
		MyLog.e("ABC", "MainTestActivity created");
		
		mButton = (Button) findViewById(R.id.jumpBtn);
		
		mButton.setText("MainButton");
		
		
		
		mButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				
				
				
				Intent i = new Intent(MainTestActivity.this,SencondTestActivity.class);
				
				startActivity(i);
				
			}
		});
		
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
	//	getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(null);
	}
	

	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		// TODO Auto-generated method stub
		super.onWindowFocusChanged(hasFocus);
		
		Log.e("ABC","onWindowFocusChanged :"+hasFocus);
		if(hasFocus){
		
			hideNavi();
			
		}
		
	}
	
	private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener = new OnSystemUiVisibilityChangeListener() {
		
		@Override
		public void onSystemUiVisibilityChange(int visibility) {
			
			
			Log.e("ABC", "onSystemUiVisibilityChange:"+visibility);
			
			if(visibility==0){
				
				mHandeler.postDelayed(new Runnable() {
					
					@Override
					public void run() {

						hideNavi();
					}
				}, delay);
				
			}else{
				
				
			}
			 
			
		}
	};
	
	

	private void hideNavi(){
		
		
		getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
				|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE); 
	}

	


}
